package com.adinall.dsp.service.impl;

import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 * 报表整合导出Excel样式
 * 
 * @author 高万超
 * @version V1.0.0 $ 2017年9月27日 下午2:12:58
 */
public class RPTExcelStyle {

    private XSSFWorkbook workbook;
    private Font font;
    private DataFormat format;

    public RPTExcelStyle(XSSFWorkbook workbook) {
        this.workbook = workbook;

        font = workbook.createFont();
        font.setFontName("微软雅黑");
        font.setFontHeightInPoints((short) 8);

        format = workbook.createDataFormat();
    }

    public CellStyle title0() {

        CellStyle style = workbook.createCellStyle();
        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        style.setFillForegroundColor(IndexedColors.LIGHT_ORANGE.index);

        style.setVerticalAlignment(VerticalAlignment.CENTER);
        style.setFont(font);

        style.setBorderTop(BorderStyle.DASHED);
        style.setBorderBottom(BorderStyle.DASHED);
        style.setBorderLeft(BorderStyle.DASHED);
        style.setBorderRight(BorderStyle.DASHED);

        return style;
    }

    public CellStyle title1() {

        CellStyle style = workbook.createCellStyle();
        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        style.setFillForegroundColor(IndexedColors.PALE_BLUE.index);

        style.setVerticalAlignment(VerticalAlignment.CENTER);
        style.setFont(font);

        style.setBorderTop(BorderStyle.DASHED);
        style.setBorderBottom(BorderStyle.DASHED);
        style.setBorderLeft(BorderStyle.DASHED);
        style.setBorderRight(BorderStyle.DASHED);

        return style;
    }

    public CellStyle content_String() {

        CellStyle style = workbook.createCellStyle();
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        style.setFont(font);

        style.setBorderTop(BorderStyle.DASHED);
        style.setBorderBottom(BorderStyle.DASHED);
        style.setBorderLeft(BorderStyle.DASHED);
        style.setBorderRight(BorderStyle.DASHED);

        return style;
    }

    public CellStyle content_int() {

        CellStyle style = workbook.createCellStyle();
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        style.setFont(font);
        style.setDataFormat(format.getFormat("#,##0"));

        style.setBorderTop(BorderStyle.DASHED);
        style.setBorderBottom(BorderStyle.DASHED);
        style.setBorderLeft(BorderStyle.DASHED);
        style.setBorderRight(BorderStyle.DASHED);

        return style;
    }

    public CellStyle content_double() {

        CellStyle style = workbook.createCellStyle();
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        style.setFont(font);
        style.setDataFormat(format.getFormat("#,##0.00"));

        style.setBorderTop(BorderStyle.DASHED);
        style.setBorderBottom(BorderStyle.DASHED);
        style.setBorderLeft(BorderStyle.DASHED);
        style.setBorderRight(BorderStyle.DASHED);

        return style;
    }
}